package com.idak.rdv.db.test;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import com.idak.rdv.db.User;
import com.idak.rdv.db.UserRole;

public class HibernateUtil {

    private static final SessionFactory sessionFactory = buildSessionFactory();

    private static SessionFactory buildSessionFactory() {
        try {
        	AnnotationConfiguration cfg = new AnnotationConfiguration().configure();
        	cfg.addAnnotatedClass(UserRole.class);
        	cfg.addAnnotatedClass(User.class);

        	return cfg.buildSessionFactory();
        }
        catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

}
